package org.wu.framework.lazy.database.datasource.proxy.handler;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * lazy connect 连接处理器
 */
public class LazyConnectionHandler extends AbstractConnectionHandler {
    /**
     * 获取事物状态
     *
     * @param dataSource 数据源
     * @param connection 数据源中的连接
     */
    @Override
    public boolean isConnectionTransactional(DataSource dataSource, Connection connection) {
        return false;
    }

    /**
     * 释放连接
     *
     * @param dataSource 数据源
     * @param connection 数据源中的连接
     */
    @Override
    public void connectionClose(DataSource dataSource, Connection connection) {
        try {
            if (connection != null && !connection.isClosed()) {
                connection.close();
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
